package com.zjc.yohoshop.mvp.view.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.zjc.yohoshop.R;
import com.zjc.yohoshop.dao.USerService;
import com.zjc.yohoshop.mvc.view.FragmentActivity;

/**
 * A simple {@link Fragment} subclass.
 */
public class SettingFragment extends Fragment implements View.OnClickListener {


    private View view;
    private CheckBox cb_setting_artwork_master;
    private CheckBox cb_setting_update;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_setting, container, false);
        initView();
        initListener();
        return view;
    }

    /**
     * 控件添加点击事件
     */
    private void initListener() {
        view.findViewById(R.id.iv_setting_back).setOnClickListener(this);//返回
        view.findViewById(R.id.ll_setting_pim).setOnClickListener(this);//个人信息
        view.findViewById(R.id.ll_setting_IPAM).setOnClickListener(this);//地址管理
        view.findViewById(R.id.ll_setting_account_safety).setOnClickListener(this);//账号安全
        view.findViewById(R.id.ll_setting_notification).setOnClickListener(this);//消息推送
//        view.findViewById(R.id.ll_setting_artwork_master).setOnClickListener(this);//2G/3G网络显示原图
//        view.findViewById(R.id.ll_setting_update).setOnClickListener(this);//wifi环境下自动更新
        view.findViewById(R.id.ll_setting_clear).setOnClickListener(this);//清除缓存
        view.findViewById(R.id.ll_setting_evaluate).setOnClickListener(this);//评价有货
        view.findViewById(R.id.ll_setting_in_regard_to).setOnClickListener(this);//关于有货
        view.findViewById(R.id.ll_setting_yoho).setOnClickListener(this);//Yoho!Now
        view.findViewById(R.id.ll_setting_mars).setOnClickListener(this);//mars
        view.findViewById(R.id.btn_setting_logout).setOnClickListener(this);//退出登录
    }

    /**
     * 初始化控件赋值
     */
    private void initView() {
        cb_setting_artwork_master = (CheckBox) view.findViewById(R.id.cb_setting_artwork_master);
        cb_setting_update = (CheckBox) view.findViewById(R.id.cb_setting_update);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_setting_back://返回
                getActivity().finish();
                break;
            case R.id.ll_setting_pim://个人信息
                Intent update_user = new Intent(getActivity(), FragmentActivity.class);
                update_user.putExtra("type", "update_user");
                getActivity().startActivity(update_user);
                break;
            case R.id.ll_setting_IPAM://地址管理
                Intent addresslist = new Intent(getActivity(), FragmentActivity.class);
                addresslist.putExtra("type", "addresslist");
                getActivity().startActivity(addresslist);
                break;
            case R.id.ll_setting_account_safety://账号安全
                break;
            case R.id.ll_setting_notification://消息推送
                break;
            case R.id.ll_setting_clear://清除缓存
                break;
            case R.id.ll_setting_evaluate://评价有货
                break;
            case R.id.ll_setting_in_regard_to://关于有货
                break;
            case R.id.ll_setting_yoho://Yoho!Now
                break;
            case R.id.ll_setting_mars://mars
                break;
            case R.id.btn_setting_logout://退出登录
                USerService.getInstance().delete("user", null, null);
                getActivity().finish();
                break;
        }
    }
}
